<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/jquery.js"></script>
</head>
<body>
<form  method="post" action="/medical/add" id="form">
    <table>
        <tr content="2">
            <th>添加核酸检查信息</th>
        </tr>
        <tr>
            <td>被检查人姓名</td>
            <td><input type="text" name="assayUser" class="yanz"></td>
        </tr>
        <tr>
            <td>被检查人手机号码</td>
            <td><input type="text" name="phone" class="yanz"></td>
        </tr>
        <tr>
            <td>被检查人身份证号</td>
            <td><input type="text" name="cardNum" class="yanz"></td>
        </tr>
        <tr>
            <td>检测机构</td>
            <td>
                <select name="hospitalId" id="hospitaId">
                    <option value="">---请选择---</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>检测日期</td>
            <td><input type="text" name="assayTime" class="yanz"></td>
        </tr>
        <tr>
            <td>
                <input type="submit" value="添加">
                <input type="button" value="返回" onclick="window.history.go(-1)">
            </td>
        </tr>
    </table>
</form>

</body>
<script>
    $(function (){
        $("#form").submit(function (data){
            for (let i = 0; i < $(".yanz").length; i++) {
                if ($(".yanz:eq("+i+")").val()==''){
                    alert("请填写完整信息")
                    return false;
                }
            }
            var zheng = /^\d{4}-\d{2}-\d{2}$/
            if (!zheng.test($(".yanz:eq(3)").val())){
                alert("日期格式不正确")
                return false;
            }
            if ($("#hospitaId").val()==''){
                alert("请选择!")
                return false;
            }
            return true;
        })


        $.ajax({
            url:"/medical/hospital",
            type:"post",
            success:function (data){
                var op = "<option value=\"\">---请选择---</option>"
                for (let i = 0; i < data.length; i++) {
                    op+='<option value='+data[i].id+'>---'+data[i].name+'---</option>'
                }
                $("#hospitaId").html(op)
            }
        })
    })
</script>
</html>